package sdm.sensor.sample;

import org.cloudminer.sensor.MyParameter;
import org.cloudminer.sensor.MySample;
import org.cloudminer.sensor.MySensor;

public class SenAppSample {

	public static void main(String args[]) {
		
		MySensor mySensor = new MySensor();
		MyParameter myParameter = new MyParameter();
		MySample mySample = null;
		
		//first test the NASDAQ sensor
		System.out.println("Test NASDAQ broker:");
		
		//specify a company code (AAPL for Apple Inc.)
		myParameter.setParameter("AAPL");
		//send a query
		mySample = mySensor.generateSample(MySensor.SENSOR_NAME_NASDAQ, myParameter);
		//output the timestamp and last sale
		System.out.println("time: " + mySample.getDateAndTime() + ", last sale: " + mySample.getValue());
		//repeat this again
		mySample = mySensor.generateSample(MySensor.SENSOR_NAME_NASDAQ, myParameter);
		System.out.println("time: " + mySample.getDateAndTime() + ", last sale: " + mySample.getValue());
		//repeat this for another enterprise
		myParameter.setParameter("MIND");
		mySample = mySensor.generateSample(MySensor.SENSOR_NAME_NASDAQ, myParameter);
		System.out.println("time: " + mySample.getDateAndTime() + ", last sale: " + mySample.getValue());
		
		//test the temperature sensor
		System.out.println("\n\nTest temperature measurement:");
		
		//specify the path of the record file written by the sensor
		myParameter.setParameter("D:\\recdata.csv");
		
		for(int index = 1; index <= 8;  index++) {
			
			//sample the temperature
			mySample = mySensor.generateSample(MySensor.SENSOR_NAME_TEMPERATURE, myParameter);
			//output the timestamp and latest temperature record if any
			System.out.println("time: " + mySample.getDateAndTime() + ", last record: " + mySample.getValue());
			//wait for 1.5 sec
			try {
				Thread.sleep(1500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
	}
}
